package com.work.saturn.assets;


import com.immo.libcommon.base.BaseHeadActivity;
import com.work.saturn.utils.ZXingUtils;
import com.work.saturn.R;

import android.annotation.SuppressLint;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * @author Administrator
 * @content 转入
 * @date 2018/7/11
 */
public class AssetsTurnInActivity extends BaseHeadActivity {
    @BindView(R.id.turn_in_zxing)
    ImageView zxing;
    @BindView(R.id.turn_in_account)
    TextView account;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_turn_in);
        ButterKnife.bind(this);
        setTitle("收款码");
        initUI();


    }

    @SuppressLint("SetTextI18n")
    private void initUI() {
        account.setText("地址：" + getIntent().getStringExtra("userId"));
        Bitmap bitmap = ZXingUtils.createQRImage(getIntent().getStringExtra("userId"), 600, 600);
        zxing.setImageBitmap(bitmap);
    }

    private void copy() {
        // 得到剪贴板管理器
        ClipboardManager clipboardManager =
                (ClipboardManager) AssetsTurnInActivity.this.getSystemService(Context.CLIPBOARD_SERVICE);
        assert clipboardManager != null;
        clipboardManager.setPrimaryClip(ClipData.newPlainText(null, getIntent().getStringExtra("userId")));
        if (clipboardManager.hasPrimaryClip()) {
            clipboardManager.getPrimaryClip().getItemAt(0).getText();
        }
        toast("已复制到粘贴板");
    }

    @OnClick({R.id.turn_in_zxing, R.id.turn_in_copy})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.turn_in_zxing:
                copy();
                break;
            case R.id.turn_in_copy:
                copy();
                break;
        }
    }
}
